<?PHP
include "utility_functions.php";

//RETRIEVE ITEMS FROM DATABASE FOR USE IN PAGE




//HOW TO DELETE FROM TABLE
//$sql = "delete from SKILL where value='desiredvalue'";
//execute_sql_in_oracle($sql);

//HOW TO INSERT INTO TABLE
//$sql = "insert into SKILL values('userid', 'skill')";
//or
//$sql = "insert into skill (userid, skill) values('userid','skill')";
//execute_sql_in_oracle($sql);
//HOW TO UPDATE ROW
//$sql = "update SKILL set skill='Carry things' where userid='userid' and skill='1111'";
//execute_sql_in_oracle($sql);

if (isset($_GET["skills"])) if ($_GET["skills"] == true){
	$sql_get_user_skill = "select skill from SKILL where UserId='".$_SESSION['user_id']."'";
	$user_skill_result = execute_sql_in_oracle($sql_get_user_skill);
	$iterations = 0;
	while ($user_skill = oci_fetch_array($user_skill_result["cursor"])){
		echo "<label id=\"oldskilllabel".$iterations."\" for=\"oldskill".$iterations."\">";
		echo "Existing Skill: ";
		echo "</label>";
		echo "<input type=\"text\" name=\"oldskill".$iterations."\" id=\"oldskill".$iterations."\" maxlength=\"50\" value=\"".$user_skill[0]."\" />";
		echo "<input type=\"hidden\" name=\"oldskilloriginal".$iterations."\" id=\"oldskilloriginal".$iterations."\" value=\"".$user_skill[0]."\" />";
		echo "<input type=\"button\" id=\"btnRemove".$iterations."\" onclick=\"deleteSkill(".$iterations.")\" value=\"Remove\" />";
		//echo "<br>";
		$iterations++;
	}
}
if (isset($_GET["avail"])) if ($_GET["avail"] == true){
	$sql_get_user_avail = "select * from AVAILABILITY where UserId='".$_SESSION['user_id']."' and day='m'";
	$user_avail_result = execute_sql_in_oracle($sql_get_user_avail);
	$user_avail = oci_fetch_array($user_avail_result["cursor"]);
	$times["m_s_time"] = substr($user_avail["S_TIME"],10,3).substr($user_avail["S_TIME"],-2,2);
	$times["m_e_time"] = substr($user_avail["E_TIME"],10,3).substr($user_avail["E_TIME"],-2,2);
	$sql_get_user_avail = "select * from AVAILABILITY where UserId='".$_SESSION['user_id']."' and day='t'";
	$user_avail_result = execute_sql_in_oracle($sql_get_user_avail);
	$user_avail = oci_fetch_array($user_avail_result["cursor"]);
	$times["t_s_time"] = substr($user_avail["S_TIME"],10,3).substr($user_avail["S_TIME"],-2,2);
	$times["t_e_time"] = substr($user_avail["E_TIME"],10,3).substr($user_avail["E_TIME"],-2,2);
	$sql_get_user_avail = "select * from AVAILABILITY where UserId='".$_SESSION['user_id']."' and day='w'";
	$user_avail_result = execute_sql_in_oracle($sql_get_user_avail);
	$user_avail = oci_fetch_array($user_avail_result["cursor"]);
	$times["w_s_time"] = substr($user_avail["S_TIME"],10,3).substr($user_avail["S_TIME"],-2,2);
	$times["w_e_time"] = substr($user_avail["E_TIME"],10,3).substr($user_avail["E_TIME"],-2,2);
	$sql_get_user_avail = "select * from AVAILABILITY where UserId='".$_SESSION['user_id']."' and day='tr'";
	$user_avail_result = execute_sql_in_oracle($sql_get_user_avail);
	$user_avail = oci_fetch_array($user_avail_result["cursor"]);
	$times["tr_s_time"] = substr($user_avail["S_TIME"],10,3).substr($user_avail["S_TIME"],-2,2);
	$times["tr_e_time"] = substr($user_avail["E_TIME"],10,3).substr($user_avail["E_TIME"],-2,2);
	$sql_get_user_avail = "select * from AVAILABILITY where UserId='".$_SESSION['user_id']."' and day='f'";
	$user_avail_result = execute_sql_in_oracle($sql_get_user_avail);
	$user_avail = oci_fetch_array($user_avail_result["cursor"]);
	$times["f_s_time"] = substr($user_avail["S_TIME"],10,3).substr($user_avail["S_TIME"],-2,2);
	$times["f_e_time"] = substr($user_avail["E_TIME"],10,3).substr($user_avail["E_TIME"],-2,2);	
	forEach($times as $key => $val){
		$timeofday = substr($val,-2,2);
		$times[$key] = substr($val,0,2);
		if ($timeofday == "PM" && $times[$key] != 12) $times[$key] += 12;
	}
	$start_hour_dropdown = "<option value=\"8\">8am</option>\n<br>
					  <option value=\"9\">9am</option>\n<br>
					  <option value=\"10\">10am</option>\n<br>
					  <option value=\"11\">11am</option>\n<br>
					  <option value=\"12\">12pm</option>\n<br>
					  <option value=\"13\">1pm</option>\n<br>
					  <option value=\"14\">2pm</option>\n<br>
					  <option value=\"15\">3pm</option>\n<br>
					  <option value=\"16\">4pm</option>\n<br>
					  <option value=\"17\">5pm</option>\n<br>
					  <option value=\"18\">6pm</option>\n<br>";
	$end_hour_dropdown = "
					  <option value=\"12\">12pm</option>\n<br>
					  <option value=\"13\">1pm</option>\n<br>
					  <option value=\"14\">2pm</option>\n<br>
					  <option value=\"15\">3pm</option>\n<br>
					  <option value=\"16\">4pm</option>\n<br>
					  <option value=\"17\">5pm</option>\n<br>
					  <option value=\"18\">6pm</option>\n<br>
					  <option value=\"19\">7pm</option>\n<br>
					  <option value=\"20\">8pm</option>\n<br>
					  <option value=\"21\">9pm</option>\n<br>
					  <option value=\"22\">10pm</option>\n<br>";
	echo "User availability:<br>";
	echo "Monday: ";
	echo "<select name=\"monday_start\" id=\"monday_start\">";
	startTime($times["m_s_time"]);
	echo "</select>";
	echo "<select name=\"monday_end\" id=\"monday_end\">";
	endTime($times["m_e_time"]);
	echo "</select><br>";
	echo "Tuesday: ";
	echo "<select name=\"tuesday_start\" id=\"tuesday_start\">";
	startTime($times["t_s_time"]);
	echo "</select>";
	echo "<select name=\"tuesday_end\" id=\"tuesday_end\">";
	endTime($times["t_e_time"]);
	echo "</select><br>";
	echo "Wednesday: ";
	echo "<select name=\"wednesday_start\" id=\"wednesday_start\">";
	startTime($times["w_s_time"]);
	echo "</select>";
	echo "<select name=\"wednesday_end\" id=\"wednesday_end\">";
	endTime($times["w_e_time"]);
	echo "</select><br>";
	echo "Thursday: ";
	echo "<select name=\"thursday_start\" id=\"thursday_start\">";
	startTime($times["tr_s_time"]);
	echo "</select>";
	echo "<select name=\"thursday_end\" id=\"thursday_end\">";
	endTime($times["tr_e_time"]);
	echo "</select><br>";
	echo "Friday: ";
	echo "<select name=\"friday_start\" id=\"friday_start\">";
	startTime($times["f_s_time"]);
	echo "</select>";
	echo "<select name=\"friday_end\" id=\"friday_end\">";
	endTime($times["f_e_time"]);
	echo "</select><br>";
}

if (isset($_GET["account"])) if ($_GET["account"] == true){
	$sql_get_account = "select * from USER_ACCT where UserId='".$_SESSION['user_id']."'";
	$user_account_result = execute_sql_in_oracle($sql_get_account);
	$user_account = oci_fetch_array($user_account_result["cursor"]);
	echo "First Name: <input type=\"text\" name=\"fname\" id=\"fname\" value=\"".$user_account['FNAME']."\" /><br>";
	echo "Last Name: <input type=\"text\" name=\"lname\" id=\"lname\" value=\"".$user_account['LNAME']."\" /><br>";
	echo "Gender: <input type=\"text\" name=\"gender\" id=\"gender\" value=\"".$user_account['GENDER']."\" />M or F<br>";
	echo "Birthday: <input type=\"text\" name=\"dob\" id=\"dob\" value=\"".$user_account['DOB']."\" /><br>";
	echo "Address: <input type=\"text\" name=\"street\" id=\"street\" value=\"".$user_account['STREET']."\" /><br>";
	echo "City: <input type=\"text\" name=\"city\" id=\"city\" value=\"".$user_account['CITY']."\" /><br>";
	echo "State: <input type=\"text\" name=\"state\" id=\"state\" value=\"".$user_account['STATE']."\" /><br>";
	echo "Zip: <input type=\"text\" name=\"zip\" id=\"zip\" value=\"".$user_account['ZIP']."\" /><br>";
	echo "Email: <input type=\"text\" name=\"email\" id=\"email\" value=\"".$user_account['EMAIL']."\" /><br>";
	echo "Phone: <input type=\"text\" name=\"phone\" id=\"phone\" value=\"".$user_account['PHONE']."\" /><br>";
	echo "Set New Password: <input type=\"password\" name=\"password\" id=\"password\" /><br>";
	if (($_SESSION['sflag'] != "y") and ($user_account['PROMO_REQUEST'] != "y") and ($user_account['PROMO_REQUEST'] != "Y"))
	echo "<input type=\"button\" value=\"Apply for Stakeholder\" onclick=\"apply()\" /><br>";
	
}

function startTime($s_time){
	for($i = 8; $i < 19; $i++){
		if ($i < 12) $var = "AM";
		else $var = "PM";
		$time = $i % 12;
		if ($time == 0) $time = 12;
		if ($i == $s_time) echo "<option value=\"".$i."\"selected>".$time.$var."</option>\n<br>";
		else echo "<option value=\"".$i."\">".$time.$var."</option>\n<br>";
	}
}
function endTime($e_time){
	for($i = 12; $i < 23; $i++){
		$time = $i % 12;
		if ($time == 0) $time = 12;
		if ($i == $e_time) echo "<option value=\"".$i."\"selected>".$time."PM</option>\n<br>";
		else echo "<option value=\"".$i."\">".$time."PM</option>\n<br>";
	}
}
?>